package com.ruan.quartz;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;  
import java.util.concurrent.TimeUnit;  

@Slf4j
public class SessionCleanupTask {
    // 使用单线程池
    private static final ScheduledExecutorService executorService =
            Executors.newScheduledThreadPool(1);

    public static void start() {
        log.info("会话清理启动了");
        executorService.scheduleAtFixedRate(SessionManager::cleanUpSessions,
                0, 10, TimeUnit.SECONDS); // 每10分钟执行一次清理
//                0, 10, TimeUnit.MINUTES); // 每10分钟执行一次清理
    }  

    public static void stop() {  
        executorService.shutdown();  
    }  
}